using System;
using Pine.SourceParser.Tree;
using System.Reflection.Emit;
using Pine.Core;

namespace Pine.CodeGen
{
	public static class ListCompressionCodeGenerator
	{
		public static void GenerateBytecode(Context ctx, Expression e, LocalBuilder lb)
		{
			ListCompression lc = (ListCompression) e;
			
			CodeGenerator.ParseRightList(ctx, lc.Content);
			
			ctx.il.Emit(OpCodes.Ldloc, ctx.list);
			ctx.il.Emit(OpCodes.Ldc_R8, 0.0);
			ctx.il.Emit(OpCodes.Call, typeof(ValueList).GetMethod("GetArrayElement", new Type[] { typeof(double) }));
			ctx.il.Emit(OpCodes.Stloc, lb);
			ctx.il.Emit(OpCodes.Ldloc, ctx.list);
			ctx.il.Emit(OpCodes.Call, typeof(ValueList).GetMethod("Clear"));
		}
	}
}

